#include "draw.h"
#include "chrset.h"
#include "io.h"

#define MAX_CX	80
#define MAX_CY	30

uint8 g_text_color = 0x0f;

void set_text_color(uint8 color)
{
	g_text_color = color;
}

uint8 get_text_color()
{
	return g_text_color;
}

void set_mode(uint8 _mode)
{
	_asm xor ax, ax
	_asm mov al, _mode
	_asm int 10h
}

void draw_pixel(uint16 _x, uint16 _y, uint8 _color)
{
	_asm mov ah, 0ch
	_asm mov cx, _x
	_asm mov dx, _y
	_asm mov al, _color
	_asm int 10h
}

void draw_hz(uint8 x, uint8 y, uint16 code)
{
	uint8 i, j, k;
	uint16 cx, cy;
	uint8 far *mask = get_chr_mask(code);
	uint8 color = get_text_color();

	if (mask == NULL)
		return;

	cx = (uint16)(x * 8);
	cy = (uint16)(y * 16);

	for (i = 0; i < 16; i++)
		for (j = 0; j < 2; j++)
			for (k = 0; k < 8; k++)
				if (mask[i * 2 + j] & (0x80 >> k))
					draw_pixel(cx + j * 8 + k, cy + i, color);
				else
					draw_pixel(cx + j * 8 + k, cy + i, 0);
}

void get_point(uint8 far *px, uint8 far *py)
{
	uint8 _x;
	uint8 _y;
	uint8 _no;

	_asm mov ah, 03h
	_asm mov bh, 00h
	_asm int 10h
	_asm mov _x, dl
	_asm mov _y, dh
	_asm mov _no, bh
	*px = _x;
	*py = _y;
}

void set_point(uint8 _px, uint8 _py)
{
	if (_px > MAX_CX - 1)
		_px = MAX_CX - 1;
	if (_py > MAX_CY - 1)
		_py = MAX_CY - 1;

	_asm mov ah, 02h
	_asm mov bh, 00h
	_asm mov dh, _py
	_asm mov dl, _px
	_asm int 10h
}

